import { createRouter, createWebHistory } from 'vue-router'
import  routes  from './routes'
import { get_token } from '@/utils/auth';
import { check_login } from '@/api/login';
import { closeloading, startloading } from '@/utils/loading';
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

/**
 * 前置守卫
 */
router.beforeEach(async(to, from, next) => {
  startloading();
  if (!to.meta.not_check) {
    if (!get_token()) {
      next('login');
      return;
    }
    const res=await check_login();
    

  }
  next();
});
router.afterEach(()=>{
  closeloading();
})

export default router
